import React, { Component } from "react";
import { connect } from "react-redux";
// import store from "./store"
class App extends Component {
  // state = {
  //   num: store.getState().num,
  // };
  render() {
    // console.log(store);
    // console.log(store.getState());
    return (
      <div>
        <button
          onClick={() => {
            // this.setState({
            //   num: this.state.num + 1,
            // });
            this.props.add();
          }}
        >
          +
        </button>
        <h1>{this.props.num}</h1>
        <button
          onClick={() => {
            // this.setState({
            //   num: this.state.num - 1,
            // });
            this.props.sub();
          }}
        >
          -
        </button>
      </div>
    );
  }
}

export default connect((state)=>{
  return {
    num:state.num
  }
},(dispatch)=>{
  // console.log(dispatch);
  return {
    add:function(){
      const addAction = {
        type:"ADD",
        payload:{
          num: 1
        }
      }
      dispatch(addAction);
    },
    sub:function(){
      const subAction = {
        type:"SUB",
        payload:{
          num: -1
        }
      }
      dispatch(subAction);
    }
  }
})(App);
